#include <iostream>
#include <vector>
#include <Vector.hpp>

using namespace std;

class Solution
{
public:
    vector<vector<int>> specialGrid(int n)
    {
        if (n == 0)
            return vector<vector<int>>(1, vector<int>(1, 0));
        int width = pow(2, n);
        vector<vector<int>> ans(width, vector<int>(width, 0));
        fillGrid(ans, width, width - 1, 0, 0);
        return ans;
    }

    int fillGrid(vector<vector<int>> &ans, int width, int x, int y, int start)
    {
        if (width == 2)
        {
            ans[y][x] = start;
            ans[y + 1][x] = start + 1;
            ans[y + 1][x - 1] = start + 2;
            ans[y][x - 1] = start + 3;
            return start + 4;
        }
        else
        {
            start = fillGrid(ans, width / 2, x, y, start);
            start = fillGrid(ans, width / 2, x, y + width / 2, start);
            start = fillGrid(ans, width / 2, x - width / 2, y + width / 2, start);
            start = fillGrid(ans, width / 2, x - width / 2, y, start);
            return start;
        }
    }
};

int main()
{
    cout << "Code3537" << endl;
    Solution s;
    Print2DVector(s.specialGrid(2));
    return 0;
}